package com.example.demo.testso.task;

import com.example.demo.testso.utils.WebSocketUtil;

import java.util.Timer;
import java.util.TimerTask;

public class TaskHandler {
    private Timer timer=new Timer();
    private TimerTask timerTask;

    //初始化
    public TaskHandler() {
        timerTask = new TimerTask() {
            @Override
            public void run() {

                if (0 != WebSocketUtil.getWebSocketArrayList().size()) {
                    WebSocketUtil.sendMessage("测试消息");
                    System.out.println("人数为：" + WebSocketUtil.getWebSocketArrayList().size());
                } else {
                    System.out.println("没人了=");
                }


            }
        };

        timer.schedule(timerTask,1000,1000);
    }
}
